//
//  AndonAnimation.m
//  Animation
//
//  Created by 董文博 on 15/1/27.
//  Copyright (c) 2015年 OA. All rights reserved.
//

#import "AndonAnimation.h"
#import <QuartzCore/CALayer.h>
#import <Foundation/NSObject.h>

@interface AndonAnimation()

@end

@implementation AndonAnimation

+ (void) alertAnimateWithDuration:(NSTimeInterval)duration View:(UIView *)view
{
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = duration;
    animation.delegate = self;
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.0, 0.0, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1.0)]];
    animation.values = values;
    [view.layer addAnimation:animation forKey:nil];
}

+(void)zhihuDailyAnimateWithView:(UIView *)view
{
    CABasicAnimation *anima0 = [CABasicAnimation animation] ;
    anima0.keyPath = @"bounds";
    anima0.removedOnCompletion = NO;
    anima0.fillMode = kCAFillModeForwards;
    anima0.duration = 2;
    anima0.toValue =[NSValue valueWithCGRect: CGRectMake(0, 0, view.frame.size.width * 1.5, view.frame.size.height * 1.5)];
    anima0.beginTime = 0;
    
    CABasicAnimation *anima1 = [CABasicAnimation animation];
    anima1.keyPath = @"opacity";
    anima1.removedOnCompletion = NO;
    anima1.fillMode = kCAFillModeForwards;
    anima1.duration = 2;
    anima1.toValue = @(0);
    anima1.beginTime = 2;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[anima0,anima1];
    group.duration = 4;
    group.removedOnCompletion = YES;
    group.fillMode = kCAFillModeForwards;
    
    [view.layer addAnimation:group forKey:nil];
}
/* The name of the transition. Current legal transition types include
* `fade', `moveIn', `push' and `reveal'. Defaults to `fade'. */
/* An optional subtype for the transition. E.g. used to specify the
 * transition direction for motion-based transitions, in which case
 * the legal values are `fromLeft', `fromRight', `fromTop' and
 * `fromBottom'. */
+ (void)transitionWithType:(NSString *)type WithSubtype:(NSString *) subtype ForView:(UIView *) view
{
    //创建CATransition对象
    CATransition *animation = [CATransition animation];
    
    //设置运动时间
    animation.duration = 2;
    
    //设置运动type
    animation.type = type;
    if (subtype != nil) {
        
        //设置子类
        animation.subtype = subtype;
    }
    
    //设置运动速度
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    
    [view.layer addAnimation:animation forKey:@"animation"];
}
@end
